package com.yjhb.android.sbz.fragment;

import android.graphics.Color;
import android.view.View;

import com.yjhb.android.sbz.adapter.PublishTaskListAdapter;
import com.yjhb.android.sbz.entity.Task;
import com.yjhb.android.sbz.entity.TaskInfo;
import com.yjhb.android.sbz.mvp.publishtask.PublishTaskListPresenter;
import com.yjhb.android.sbz.mvp.publishtask.PublishTaskListView;
import com.yjhb.android.sbz.tool.Tool;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2021/1/8 10:07
 */
public class PublishTaskListFragment extends BaseListFragment<PublishTaskListPresenter, PublishTaskListAdapter, TaskInfo> implements PublishTaskListView {
    private final String TAG = "PublishTaskListFragment";

    private Integer userId;

    @Override
    protected PublishTaskListAdapter getAdapter() {
        return new PublishTaskListAdapter(getContext());
    }

    @Override
    protected CharSequence getTips() {
        return null;
    }

    @Override
    protected void initUI() {
        content_layout.setBackgroundColor(Color.WHITE);
        super.initUI();
    }

    @Override
    protected void onLoadData(int size, int current) {
        presenter.getPublishTaskList(userId, size, current);
    }

    @Override
    protected PublishTaskListPresenter initPresenter() {
        return new PublishTaskListPresenter(this);
    }

    @Override
    public void onItemClick(int index, Object o) {
        Task task = (Task) o;
        Tool.startEditTaskDetailActivity(getContext(), task.getId());
    }

    @Override
    public void onViewClick(View view, String msg, int index, Object o) {

    }


    @Override
    public void load(List<TaskInfo> data) {
        loadingDialog.cancel();
        smartRefreshLayout.finishLoadmore();
        if (data != null) {
            dataSet.addAll(data);
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    public void refresh(List<TaskInfo> data) {
        loadingDialog.cancel();
        smartRefreshLayout.finishRefresh();
        dataSet.clear();
        if (data != null) {
            dataSet.addAll(data);
        }
        adapter.notifyDataSetChanged();
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }
}
